export const Drag = {
  _dragElements: new Map(),  // 拖拽的元素
  // 拖拽中
  _drag(evt) {
    Drag._dragElements.forEach((elem) => {
      const { node } = elem;
      if (elem.dragStatus !== "dragging") {
        node.startDrag(evt);
      }
      node._setDragPosition(evt, elem);
    });
  },
  _endDragBefore(evt) {
    Drag._dragElements.forEach((elem, key) => {
      elem.node.getLayer().draw();
    });
  },
  _endDragAfter(evt) {
    Drag._dragElements.forEach((elem, key) => {
      Drag._dragElements.delete(key);
    });
  },
};

window.addEventListener("mouseup", Drag._endDragBefore, true);
window.addEventListener("mousemove", Drag._drag);
window.addEventListener("mouseup", Drag._endDragAfter, false);
